package aliyunCli

import (
	"fmt"
	"tushare/conf"

	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

type CreateInstance struct {
}

func (ci CreateInstance) CreateInstance(regionId, zoneId, instanceType string) string {
	client, err := ecs.NewClientWithAccessKey(regionId, conf.AccessKeyID, conf.AccessKeySecret)

	request := ecs.CreateCreateInstanceRequest()
	request.Scheme = "https"

	request.AutoRenew = requests.NewBoolean(false)
	//ecs.t6-c1m1.large ecs.c6a.xlarge
	request.InstanceType = instanceType                         //实例的资源规格
	request.ImageId = "centos_7_8_x64_20G_alibase_20211028.vhd" //镜像文件ID
	request.InstanceName = "hadoop"                             //实例的名称
	request.InternetMaxBandwidthIn = requests.NewInteger(100)   //公网入带宽最大值
	request.InternetMaxBandwidthOut = requests.NewInteger(100)  //公网出带宽最大值
	request.HostName = "hadoop001"                              //云服务器的主机名
	request.Password = "Hadoop123456"                           //实例的密码
	request.ZoneId = zoneId                                     //实例所属的可用区ID
	request.Description = "自动创建测试"                              //实例的描述
	request.InstanceChargeType = "PostPaid"                     //付费方式(按量)
	request.SecurityGroupId = "sg-bp1e8z8i5z2u62dmxv7h"         //安全组

	response, err := client.CreateInstance(request)
	if err != nil {
		fmt.Print(err.Error())
	}
	//fmt.Println(response.InstanceId)
	return response.InstanceId
	// si := new(StartInstance)
	// si.StartInstance(response.InstanceId)
}
